package com.demo.feign.impl;

import com.demo.feign.UserService;
import com.demo.feign.dto.UserDTO;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @description:
 * @author: Linyb
 * @date : 2020/11/27 14:13
 **/
@RestController
@Api(value = "user-api", description = "用户api", tags = {"user-api"})
@RequestMapping(value = UserService.INTER_NAME)
@Slf4j
public class UserServiceImpl implements UserService{

    @Override
    @ApiOperation(value = "根据id查找用户", tags = {"user-api"}, nickname = "getUserById")
    @ApiImplicitParam(value = "编号",name = "id",paramType = "path")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "200:成功，否则失败")})
    public UserDTO getUserById(@PathVariable("id") Long id) {
        if(id == 1){
            throw new RuntimeException("服务器异常");
        }else if(id == 2){
            try {
                log.info("处理中....,,");
                Thread.sleep(9999999);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        UserDTO userDTO = new UserDTO();
        userDTO.setId(id);
        userDTO.setUserName("zhangsan-"+new Random().nextInt(10));
        return userDTO;
    }
}
